<?php

namespace app\index\controller;

use app\index\model\Banner;
use app\index\model\Message;
use app\index\model\Nav;
use app\index\model\Nav as NavModel;
use think\Request;
use app\index\model\Resource as ResourceModel;
use app\index\model\Honor as HonorModel;

class Index extends BaseController
{

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    /**
     * 首页
     * @return string
     * @throws \think\Exception
     */
    public function index(NavModel $navModel)
    {
        //轮播图
        $banner = Banner::getBanner('index');
        //企业新闻
        $this->news();
        //合作伙伴
        $this->client();
        //海量资源
        $resources = ResourceModel::getAll();
        //荣誉资质
        $honors = HonorModel::getAll();

        $this->assign('banner', $banner);
        $this->assign('resources', $resources);
        $this->assign('honors', $honors);
        return $this->view->fetch();
    }

    /**
     * 留言
     */
    public function message(Request $request)
    {
        $data = $request->post();
        $data['createtime'] = time();
        $data['updatetime'] = time();
        $res = Message::create($data);
        $res ? $this->successes(null, '留言成功，请等待联系') : $this->errorMsg('服务器异常，请联系管理员');
    }

    private function errorPage($page)
    {
        if (!$page) {
            $this->error('页面丢失', null, '', 1);
        }
    }
}
